<template>
  <el-dialog :visible.sync="open" @close="close" :title="title" width="80%" append-to-body destory-on-close>
    <el-table :data="list">
      <el-table-column label="消息类型" align="center" prop="planName" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.type == 1">系统消息</span>
          <span v-if="scope.row.type == 2">事件消息</span>
          <span v-if="scope.row.type == 3">处置消息</span>
          <span v-if="scope.row.type == 4">演练情景消息</span>
        </template>
      </el-table-column>
      <el-table-column label="消息内容" align="left" prop="message" />
      <el-table-column label="操作" align="center" fixed="right" width="120">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-check" @click="handleSelectMsg(scope.row)">选择</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getMessages" />
  </el-dialog>
</template>
<script>
import dialogMixin from '../../../mixins/dialogMixin'
import * as MsgApi from '@/api/msg/message';

export default {
  name: 'MessagePickerDialog',
  mixins: [dialogMixin],
  components: {},
  props: [],
  data() {
    return {
      title: '',
      list: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getMessages();
  },
  mounted() { },
  methods: {
    getMessages() {
      MsgApi.getMessageList(this.queryParams).then(res => {
        this.total = res.total;
        res.rows.forEach(element => {
          element.type = Number(element.type)
        });
        this.list = res.rows;
      })
    },
    showDialog() {
      this.title = '选择我的消息';
      this.open = true;
    },
    handleQuery() {
      this.getMessages();
    },
    handleSelectMsg(data) {
      this.$emit('handleOk', data);
      this.open = false;
    }
  }
}

</script>
<style>
</style>
